function checkusername() {
	if(username1.value.length < 3 || username1.value.length > 8) {
		document.getElementById("errorTxt").innerHTML = "<strong >Error! 用户名格式有误请重新输入!</strong>";
		document.getElementById("errorTxt").setAttribute("class", "errorTxt");
		username1.focus();
		setTimeout(clearerror, 3000);
		return false;
	}
	else{
		return true
	}
}

function checkemail() {
	var aite = email.value.indexOf("@");
	var dian = email.value.indexOf(".");
	if(email.value == "" || email.value == null) {
		document.getElementById("errorTxt").innerHTML = "<strong>Error!!</strong> 邮箱地址不能为空请重新输入";
		document.getElementById("errorTxt").setAttribute("class", "errorTxt");
		email.focus();
		setTimeout(clearerror, 3000);
		return false;
	} else if(aite < 0) {
		document.getElementById("errorTxt").setAttribute("class", "errorTxt");
		document.getElementById("errorTxt").innerHTML = "<strong>Error!!</strong> 邮箱格式有误请重新输入";
		email.focus();
		setTimeout(clearerror, 3000);
		return false;

	} else if(dian < 0) {
		document.getElementById("errorTxt").setAttribute("class", "errorTxt");
		document.getElementById("errorTxt").innerHTML = "<strong>Error!!</strong> 邮箱格式有误请重新输入";
		email.focus();
		setTimeout(clearerror, 3000);
		return false;

	} else if(aite < 1 || dian < 3) {
		document.getElementById("errorTxt").setAttribute("class", "errorTxt");
		document.getElementById("errorTxt").innerHTML = "<strong>Error!!</strong> 邮箱格式有误请重新输入";
		email.focus();
		setTimeout(clearerror, 3000);
		return false;
	} else if(email.value.length < 5) {
		document.getElementById("errorTxt").setAttribute("class", "errorTxt");
		document.getElementById("errorTxt").innerHTML = "<strong>Error!!</strong> 邮箱格式有误请重新输入";
		email.focus();
		setTimeout(clearerror, 3000);
		return false;

	}
	else{
		return true
	}
}

function checkphone() {
	if(phone.value.length !== 11) {
		document.getElementById("errorTxt").setAttribute("class", "errorTxt");
		document.getElementById("errorTxt").innerHTML = "<strong>Error!!</strong> 手机号码格式有误请重新输入";
		phone.focus();
		setTimeout(clearerror, 3000);
		return false;
	}
	if(isNaN(phone.value)) {
		document.getElementById("errorTxt").setAttribute("class", "errorTxt");
		document.getElementById("errorTxt").innerHTML = "<strong>Error!!</strong> 手机号码格式有误请重新输入";
		phone.focus();
		setTimeout(clearerror, 3000);
		return false;
	}
	else{
		return true
	}
}
//身份证号码为15位或者18位，15位时全为数字，18位前17位为数字，最后一位是校验位，可能为数字或字符X 
function checkidCard() {
	var number = idCard.value;
	if(number.length == 15 && !isNaN(number)) {
		return true;
		} else if(number.length == 18) {
		var num = new Array();
		num = number;
		var last = num[num.length - 1];
		if(isNaN(number)) {
			if(last == "X") {
				return true;
			} else {
				document.getElementById("errorTxt").setAttribute("class", "errorTxt");
				document.getElementById("errorTxt").innerHTML = "<strong>Error!!</strong> 身份证号码格式有误请重新输入";
				idCard.focus();
				setTimeout(clearerror, 3000);
				return false;
			}
		}
		else if(!isNaN(number)) {
			return true;
		}
		else{
			return true
		}
	} else if(number == null || number == "") {
		document.getElementById("errorTxt").setAttribute("class", "errorTxt");
		document.getElementById("errorTxt").innerHTML = "<strong>Error!!</strong> 身份证号码不能为空";
		idCard.focus();
		setTimeout(clearerror, 3000);
		return false;
	} else {
		document.getElementById("errorTxt").setAttribute("class", "errorTxt");
		document.getElementById("errorTxt").innerHTML = "<strong>Error!!</strong> 身份证号码格式有误请重新输入";
		idCard.focus();
		setTimeout(clearerror, 3000);
	}
	
}

function checkpassword() {
	var password_length = password1.value.length;
	var passwordval = new Array();
	passwordval = password1.value;
	var hnum = false;
	var hasnum = false;
	for(var i = 0; i < passwordval.length; i++) {
		hashum = !isNaN(passwordval[i]);
		if(hashum) {
			hnum = true;
		}
	}
	if(!IsUpper(passwordval[0]) || !isNaN(passwordval[0])) {
		document.getElementById("errorTxt").setAttribute("class", "errorTxt");
		document.getElementById("errorTxt").innerHTML = "<strong>Error!!</strong> 首字母必须大写请重新输入";
		password.focus();
		setTimeout(clearerror, 3000);
	} else if(password_length < 6 || password_length > 16) {
		document.getElementById("errorTxt").setAttribute("class", "errorTxt");
		document.getElementById("errorTxt").innerHTML = "<strong>Error!!</strong> 密码长度与格式不符请重新输入";
		password.focus();
		setTimeout(clearerror, 3000);
	} else if(!hnum) {
		document.getElementById("errorTxt").setAttribute("class", "errorTxt");
		document.getElementById("errorTxt").innerHTML = "<strong>Error!!</strong> 密码必须使用英文字母和数字结合请重新输入";
		password.focus();
	}
	else{
		return true
	}

}

function clearerror() {
	document.getElementById("errorTxt").innerHTML = "";
	document.getElementById("errorTxt").setAttribute("class", "")
}
//验证大小写，大写返回true小写返回false
function IsUpper(code) {
	return code === code.toUpperCase(); //验证是否等于原来的数值
}

function checksum() {
	var sum = document.getElementById(sum);
	var username = document.getElementById("username1").value;
	var password = document.getElementById("password1").value;
	var email = document.getElementById("email").value;
	var phone = document.getElementById("phone").value;
	var idCard = document.getElementById("idCard").value;

	if(username == null || username == "") {
			document.getElementById("errorTxt").innerHTML = "<strong >Error! 用户名不能为空</strong>";
		document.getElementById("errorTxt").setAttribute("class", "errorTxt");
		setTimeout(clearerror, 3000);
		return false;
	}
	else if(password == null || password == "") {
		document.getElementById("errorTxt").innerHTML = "<strong >Error! 密码不能为空</strong>";
		document.getElementById("errorTxt").setAttribute("class", "errorTxt");
		setTimeout(clearerror, 3000);
		return false;
	}
	else if(email == null || email == "") {
		document.getElementById("errorTxt").innerHTML = "<strong >Error! 邮箱地址不能为空</strong>";
		document.getElementById("errorTxt").setAttribute("class", "errorTxt");
		setTimeout(clearerror, 3000);
		return false;
	}
	else if(idCard == null || idCard == "") {
		document.getElementById("errorTxt").innerHTML = "<strong >Error! 手机号码不能为空</strong>";
		document.getElementById("errorTxt").setAttribute("class", "errorTxt");
		setTimeout(clearerror, 3000);
		return false;
	}
	else if(username == null || username == "") {
		document.getElementById("errorTxt").innerHTML = "<strong >Error! 身份证号码不能为空</strong>";
		document.getElementById("errorTxt").setAttribute("class", "errorTxt");
		setTimeout(clearerror, 3000);
		return false;
	}
	else{
		console.log(username);
		return true
	}
}

function sumon() {
	var data_form = $("#myFo").serialize();
	$.ajax({
		type: "post",
		url: "/Login_Demo/user/register",
		async: true,
		data: data_form,
		dataType: 'json',
		success: function action() {
			top.location = "success.html"
		},
		error: function(xhr) {
			document.getElementById("errorTxt").innerHTML = "<strong >Error! 用户名格式有误请重新输入!</strong>";
			document.getElementById("errorTxt").setAttsribute("class", "errorTxt");
			username.focus();
			setTimeout(clearerror, 3000);
		}

	});
}
